package com.xbongbong.saas.enums;

import com.xbongbong.i18n.util.I18nMessageUtil;
import lombok.Getter;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * @author feng.zheng
 * @version v1.0
 * @date 2019/5/21 15:20
 * @since v1.0
 */
@Getter
public enum FormConfigEnum {
    //
    CUSTOMER_NAME_CHECK_SET("customerNameCheck", "customer_name_check", "enum.formConfig.name.customer_name_check_set", "1", XbbRefTypeEnum.CUSTOMER_MANAGEMENT.getCode()),
    CUSTOMER_PHONE_CHECK_SET("customerPhoneCheck", "customer_phone_check", "enum.formConfig.name.customer_phone_check_set", "1", XbbRefTypeEnum.CUSTOMER_MANAGEMENT.getCode()),
//    PRICE_ASSOCIATION("priceAssociation", "price_association", "销售价格关联", "0", XbbRefTypeEnum.CONTRACT.getCode()),
    // 客户名称全局判重： 0 不判重  1 模板内判重   2 客户全局判重
    CUSTOMER_NAME_REPEAT_TYPE("customerNameRepeatType", "customer_name_repeat_type", "enum.formConfig.name.customer_name_repeat_type", "1", XbbRefTypeEnum.CUSTOMER_MANAGEMENT.getCode()),
    // 客户电话全局判重： 0 不判重  1 模板内判重   2 客户全局判重
    CUSTOMER_PHONE_REPEAT_TYPE("customerPhoneRepeatType", "customer_phone_repeat_type", "enum.formConfig.name.customer_phone_repeat_type", "1", XbbRefTypeEnum.CUSTOMER_MANAGEMENT.getCode()),
    // 客户最后跟进时间： 0 年月日时分  1 显示为三天内、一周内等时间段样式
    CUSTOMER_LAST_CONNECT_TIME("customerLastConnectTime", "customer_last_connect_time", "enum.formConfig.name.customer_last_connect_time", "1", XbbRefTypeEnum.CUSTOMER_MANAGEMENT.getCode()),
    /**
     * 合同
     */
    CONTRACT_AMOUNT_EQUAL_REPAYMENT_PLAN("contractAmountEqualRepaymentPlan", "contract_amount_equal_repayment_plan", "enum.formConfig.name.contract_amount_equal_repayment_plan", "0", XbbRefTypeEnum.CONTRACT.getCode()),
    CONTRACT_ALLOW_OUTSTOCK_PRODUCT_NUM_LARGER_SOLD("contractAllowOutstockProductNumLargerSold", "contract_allow_outstock_product_num_larger_sold", "enum.formConfig.name.contract_allow_outstock_product_num_larger_sold", "0", XbbRefTypeEnum.CONTRACT.getCode()),

    CONTRACT_EDITABLE_PERMISSIONS_OWNER("contractEditablePermissionsOwner", "contract_editable_permissions_owner", "enum.formConfig.name.contract_editable_permissions_owner", "1", XbbRefTypeEnum.CONTRACT.getCode()),

    CONTRACT_EDITABLE_PERMISSIONS_CO_USER("contractEditablePermissionsCoUser", "contract_editable_permissions_co_user", "enum.formConfig.name.contract_editable_permissions_co_user", "0", XbbRefTypeEnum.CONTRACT.getCode()),

    CONTRACT_EDITABLE_PERMISSIONS_CREATOR("contractEditablePermissionsCreator", "contract_editable_permissions_creator", "enum.formConfig.name.contract_editable_permissions_creator", "0", XbbRefTypeEnum.CONTRACT.getCode()),

    CONTRACT_SCREENING_AUTHORIZATION_ROLE("contractScreeningAuthorizationRole", "contract_screening_authorization_role", "enum.formConfig.name.contract_screening_authorization_role", "{role:[1,2]}", XbbRefTypeEnum.CONTRACT.getCode()),

//    CONTRACT_OUTSTOCK_ALLOW_DIFFERENT_PRODUCT_TYPES("contractOutstockAllowDifferentProductTypes", "contract_outstock_allow_different_product_types", "允许合同出库产品种类与关联产品不同", "0", XbbRefTypeEnum.CONTRACT.getCode()),
//    CONTRACT_OUTSTOCK_ALLOW_DIFFERENT_PRODUCT_NUM("contractOutstockAllowDifferentProductNum", "contract_outstock_allow_different_product_num", "允许合同出库产品数量与关联产品不同", "0", XbbRefTypeEnum.CONTRACT.getCode()),
    /**
     * 跟进记录
     */
    CUSTOMER_COMMUNICATE_LOCATION_CHECK_SET("cstomerCommunicateLocationCheck", "customer_communicate_location_check", "enum.formConfig.name.customer_communicate_location_check_set", "1", XbbRefTypeEnum.CUSTOMER_COMMUNICATE.getCode()),
    CALL_AUTO_ADD_CUSTOMER_COMMUNICATE("callAutoAddCustomerCommunicate", "call_auto_add_customer_communicate", "enum.formConfig.name.call_auto_add_customer_communicate", "0", XbbRefTypeEnum.CUSTOMER_COMMUNICATE.getCode()),
    SUPPLIER_COMMUNICATE_LOCATION_CHECK_SET("supplierCommunicateLocationCheck", "supplier_communicate_location_check", "enum.formConfig.name.supplier_communicate_location_check_set", "1", XbbRefTypeEnum.SUPPLIER_COMMUNICATE.getCode()),
    /**
     * 采购合同
     */
    PURCHASE_PRODUCT_MUST_BELONG_SUPPLIER("purchaseProductMustBelongSupplier", "purchase_product_must_belong_supplier", "enum.formConfig.name.purchase_product_must_belong_supplier", "0", XbbRefTypeEnum.PURCHASE.getCode()),
    PURCHASE_AMOUNT_EQUAL_PAYMENT_PLAN("purchaseAmountEqualPaymentPlan", "purchase_amount_equal_payment_plan", "enum.formConfig.name.purchase_amount_equal_payment_plan", "0", XbbRefTypeEnum.PURCHASE.getCode()),
    /**
     * 客户阶段按钮
     */
    CUSTOMER_CROSS_STAGE_BUTTON("customerCrossStageButton", "customer_cross_Stag_button", "enum.formConfig.name.customer_cross_stag_button","1", XbbRefTypeEnum.CUSTOMER_MANAGEMENT.getCode()),
    CUSTOMER_BACK_STAGE_BUTTON("customerBackStageButton", "customer_back_stage_button", "enum.formConfig.name.customer_back_stage_button","1", XbbRefTypeEnum.CUSTOMER_MANAGEMENT.getCode()),
    /**
     * 销售阶段的按钮
     */
    SALE_CROSS_STAGE_BUTTON("saleCrossStageButton", "sale_cross_Stag_button", "enum.formConfig.name.sale_cross_stag_button", "1", XbbRefTypeEnum.SALES_OPPORTUNITY.getCode()),
    SALE_BACK_STAGE_BUTTON("saleBackStageButton", "sale_back_stage_button", "enum.formConfig.name.sale_back_stage_button", "1", XbbRefTypeEnum.SALES_OPPORTUNITY.getCode()),
    /**
     * 线索阶段按钮
     */
    CLUE_CROSS_STAGE_BUTTON("clueCrossStageButton", "clue_cross_Stag_button", "enum.formConfig.name.clue_cross_stag_button","1", XbbRefTypeEnum.CLUE.getCode()),
    CLUE_BACK_STAGE_BUTTON("clueBackStageButton", "clue_back_stage_button", "enum.formConfig.name.clue_back_stage_button","1", XbbRefTypeEnum.CLUE.getCode()),
    /**
     * 出库单
     */
    // 库存不足不允许出库 1表示禁止0表示允许负库存
    OUTSTOCK_INSUFFICIENT_NOT_ALLOW_WAREHOUSING("outstockInsufficientNotAllowWarehousing", "outstock_insufficient_not_allow_warehousing", "enum.formConfig.name.outstock_insufficient_not_allow_warehousing", "1", XbbRefTypeEnum.OUTSTOCK.getCode()),
    OUTSTOCK_DISPLAY_SALE_PRICE("outstockDisplaySalePrice", "outstock_display_sale_price", "enum.formConfig.name.outstock_display_sale_price", "0", XbbRefTypeEnum.OUTSTOCK.getCode()),

    /**
     * 生产单
     */
    PRODUCTION_ORDER_AUTO_UPDATE_NEW_CONTRACT("productionOrderAutoUpdateNewContract", "production_order_auto_update_new_contract", "enum.formConfig.name.production_order_auto_update_new_contract", "1", XbbRefTypeEnum.PRODUCTION_ORDER.getCode()),
    PRODUCTION_ORDER_AUTO_UPDATE_IMPORT_CONTRACT("productionOrderAutoUpdateImportContract", "production_order_auto_update_import_contract", "enum.formConfig.name.production_order_auto_update_import_contract", "0", XbbRefTypeEnum.PRODUCTION_ORDER.getCode()),

    // 销售机会最后跟进时间： 0 年月日时分  1 显示为三天内、一周内等时间段样式
    SALES_OPPORTUNITY_LAST_CONNECT_TIME("salesOpportunityLastConnectTime", "sales_opportunity_last_connect_time", "enum.formConfig.name.sales_opportunity_last_connect_time", "1", XbbRefTypeEnum.SALES_OPPORTUNITY.getCode()),


    // 线索名称全局判重： 0 不判重  1 模板内判重   2 线索全局判重
    CLUE_NAME_REPEAT_TYPE("clueNameRepeatType", "clue_name_repeat_type", "enum.formConfig.name.clue_name_repeat_type", "1", XbbRefTypeEnum.CLUE.getCode()),
    // 线索电话全局判重： 0 不判重  1 模板内判重   2 线索全局判重
    CLUE_PHONE_REPEAT_TYPE("cluePhoneRepeatType", "clue_phone_repeat_type", "enum.formConfig.name.clue_phone_repeat_type", "1", XbbRefTypeEnum.CLUE.getCode()),
    // 线索最后跟进时间： 0 年月日时分  1 显示为三天内、一周内等时间段样式
    CLUE_LAST_CONNECT_TIME("clueLastConnectTime", "clue_last_connect_time", "enum.formConfig.name.clue_last_connect_time", "1", XbbRefTypeEnum.CLUE.getCode()),
    // 启用发货流程管理
    ENABLE_SHIPPING_PROCESS("enableShippingProcess", "enable_shipping_process", "enum.formConfig.name.enable_shipping_process", "1", XbbRefTypeEnum.CONTRACT_OUTSTOCK.getCode()),
    // 机会名称全局判重： 0 不判重  1 模板内判重   2 线索全局判重
    OPPORTUNITY_NAME_REPEAT_TYPE("opportunityNameRepeatType", "opportunity_name_repeat_type", "enum.formConfig.name.opportunity_name_repeat_type", "1", XbbRefTypeEnum.SALES_OPPORTUNITY.getCode()),
    // 产品数据共享/隔离设置 1数据隔离  0数据共享
    PRODUCT_DATA_ISOLATION("productDataIsolation","product_data_isolation","enum.formConfig.name.product_data_isolation","0",XbbRefTypeEnum.PRODUCT.getCode()),

    ;

    /**
     * 配置别名
     */
    private final String config;
    /**
     * 数据库字段
     */
    private final String dbAlias;
    /**
     * 配置名称
     */
    private final String name;
    /**
     * 配置值
     */
    private final String configValue;
    /**
     * 业务类型
     */
    private Integer businessType;

    FormConfigEnum(String config, String dbAlias, String name, String configValue, Integer businessType) {
        this.config = config;
        this.name = name;
        this.dbAlias = dbAlias;
        this.configValue = configValue;
        this.businessType = businessType;
    }
    public static List<FormConfigEnum> getByBusinessType(Integer businessType) {
        List<FormConfigEnum> list = new ArrayList<>();
        for (FormConfigEnum formConfigEnum : FormConfigEnum.values()) {
            if (Objects.equals(businessType, formConfigEnum.getBusinessType())) {
                list.add(formConfigEnum);
            }
        }
        return list;
    }
    public static FormConfigEnum getByConfig(String config) {
        FormConfigEnum configEnum = null;
        for (FormConfigEnum formConfigEnum : FormConfigEnum.values()) {
            if (Objects.equals(config, formConfigEnum.getConfig())) {
                configEnum = formConfigEnum;
            }
        }
        return configEnum;
    }

    public String getName() {
        return I18nMessageUtil.getMessage(name);
    }
}
